using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading;
using System.Xml;
using NUnit.Framework;
using Universe.Farm.Builtin.LocalComputerListener;
using Universe.Farm.Service;

namespace Universe.Farm.Tests
{
    
    [TestFixture]
    public class TestInprocess
    {
        private Service.Farm _farm = null;
        private ConfigurationContainer _config;

        [TestFixtureSetUp]
        public void SetUp()
        {
            _config = MyEnvironment.CreateConfiguration(TimeSpan.FromSeconds(100));
            _farm = new Service.Farm(_config);
            _farm.Start();
        }
        
        [Test]
        public void Run()
        {
            // Thread.Sleep(5000);

            ServicesScope waitScope =
                ServicesScope.Empty
                .Add(Environment.MachineName, "ComputerInfo")
                .Add(Environment.MachineName, "LocalSqlServer");

            MyEnvironment.Wait(_farm, waitScope, TimeSpan.FromSeconds(10));


            IList<HealthInfo> allFound = _farm.LocalInfo.GetServices(ServicesScope.FullScope);
            Assert.GreaterOrEqual(allFound.Count, 2, "2 service health is available");

            IList<HealthInfo> myServices = _farm.LocalInfo.GetServices(ServicesScope.Empty.Add(Environment.MachineName, "ComputerInfo"));
            HealthInfo healthInfo = myServices.Count == 0 ? null : myServices[0];
            Assert.IsNotNull(healthInfo, "there is a computer info");

            ComputerInfoDescription computerInfo = healthInfo.DescriptionBuffer.Get<ComputerInfoDescription>();
            Assert.Greater(computerInfo.NumberOfProcessors, 0, "There is a processor");
            Assert.Greater(computerInfo.PhysicalMemory, 0, "There is a memory");
            Assert.IsNotNull(computerInfo.OsName, "There is an OS");
        }

        [TestFixtureTearDown]
        public void TearDown()
        {
            _farm.Stop();
        }

    }


}
